﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ECare.BUS.Data;
using ECare.Database;

namespace ECare.BUS
{
    public class StackerInfoHelper
    {
        public static int CreateStackInfo(StackerInfo stacker)
        {
            using (var context = new Entities())
            {
                var newstacker = new stacker();
                newstacker.stacker_code = stacker.StackerInfo_Code;
                newstacker.stacker_name = stacker.StackerInfo_Name;
                context.stackers.AddObject(newstacker);

        
                context.SaveChanges();

                return newstacker.stacker_id;
            }
        }

        public static bool UpdateStacker(StackerInfo stacker)
        {
            using (var context = new Entities())
            {
                var newstacker = context.stackers.FirstOrDefault(a => a.stacker_id == stacker.StackerInfo_Id);
                if (newstacker == null)
                    return false;

                newstacker.stacker_code = stacker.StackerInfo_Code;
                newstacker.stacker_name = stacker.StackerInfo_Name;
                context.SaveChanges();

                return false;
            }
        }


        public static List<StackerInfo> GetStackers()
        {
            using (var context = new Entities())
            {
                var stackers = context.stackers;
                var res = new List<StackerInfo>();


                foreach (var stacker in stackers)
                {
                    var info = new StackerInfo();
                    info.StackerInfo_Id = stacker.stacker_id;
                    info.StackerInfo_Code = stacker.stacker_code;
                    info.StackerInfo_Name = stacker.stacker_name;

                    res.Add(info);
                }
                return res;
            }
        }



        



    }
}
